package cn.wwcyc.domain;

import cn.wwcyc.exception.WWExceptionEnum;
import lombok.Data;

@Data
public class R <T>{
    private Integer code;
    private String message;
    private T data;
    private static final Integer SUCCESS = 20000;
    private static final String SUCCESS_MESSAGE = "sucess！";
    public R() {
        this.code = SUCCESS;
        this.message = SUCCESS_MESSAGE;
//        this.data = null;
    }
    public R(Integer code, String message){
        this.code = code;
        this.message = message;
//        this.data = null;
    }
    public R(Integer code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public static <T> R<T> success(){
        return new R<>();
    }
    public static <E> R<E> success(E data){
        R<E> r = new R<>();
        r.setData(data);
        return r;
    }
    public static <E> R<E> error(Integer code, String message){
        return new R<>(code, message);
    }
    public static <E> R<E> error(WWExceptionEnum exenum){
        return new R<>(exenum.getCode(), exenum.getMessage());
    }

//    public <T> T test(T e){//此处的T会隐藏外面的
//        return e;
//
//    }
//
//    public static void main(String[] args) {
//        R<User> r = new R<User>();
//        City city = new City();
//        System.out.println(r.test(city));
//        System.out.println(r);
//        User u  = new User();
//        R.success(u);
//    }
}
